package BanyuanClub.Study.Day0308.多线程.习题一;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

public class Text3 {
    public static void main(String[] args)  {
        int[] arr = {1,2,3,4,5,6,7,8,9};
        class sumCall implements Callable<Integer>{
            int sum = 0;
            boolean b;

            public sumCall(boolean b) {
                this.b = b;
            }

            public int getSum() {
                return sum;
            }
            @Override
            public Integer call() throws Exception {
                for (int i = this.b == true ? 0 : 1; i < arr.length; i+=2) {
                    sum += arr[i];
                    System.out.println(Thread.currentThread() + "--" + i) ;
                }
                return sum;
            }
        }

        FutureTask ft1 = new FutureTask(new sumCall(true));
        FutureTask ft2 = new FutureTask(new sumCall(false));
        Thread th1 = new Thread(ft1);
        Thread th2 = new Thread(ft2);
//        System.out.println(ft1.get() + ft2.get());
    }
}
